﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProjectCore.Application;
using ProjectCore.Application.AppUser.Dto;
using ProjectCore.Common;
using ProjectCore.Domain.Model.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ProjectCore.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class OrderController : ControllerBase
    {
        private readonly IAppOrder appOrder;
        public OrderController(IAppOrder _appAdmin)
        {
            appOrder = _appAdmin;
        }
        /// <summary>
        /// 获取订单表集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetOrders(int SendId = 0, DateTime? Begin = null, DateTime? End = null, string Na = "", int pageIndex = 0, int pageSize = 0)
        {
            Task<HeaderResult<List<UserOrderPro>>> orders = appOrder.GetOrders(SendId, Begin, End, Na, pageIndex, pageSize);
            return Ok(await orders);
        }


        /// <summary>
        /// 获取订单数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetOrder(int Id)
        {
            Task<Order> order = appOrder.GetOrder(Id);
            return Ok(new
            {
                data = await order
            });
        }


        /// <summary>
        /// 批量发货
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> UptState(string Id)
        {
            Task<int> n = appOrder.UptState(Id);
            return Ok(new
            {
                data = await n
            });
        }


        /// <summary>
        /// 获取地址数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetStie(int Id)
        {
            Task<Site> site = appOrder.GetSite(Id);
            return Ok(new
            {
                data = await site
            });
        }


        /// <summary>
        /// 获取支付数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> GetPay(int Id)
        {
            Task<Pay> pay = appOrder.GetPay(Id);
            return Ok(new
            {
                data = await pay
            });
        }
    }
}
